﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
    string appId = ConfigurationManager.AppSettings["AppId"];
    string appSecret = ConfigurationManager.AppSettings["AppSecret"];
    string redirectUrl = ConfigurationManager.AppSettings["RedirectUrl"];
    string scope = ConfigurationManager.AppSettings["scope"];

    protected void Page_Load(object sender, EventArgs e)
    {
        // Steps to be followed:
        // In the web.config set values for AppId,AppSecret,Scope and RedirectUrl
        // The redirect url should refer to a path inside the Canvas url of the application.
        if (Request.QueryString["code"] != null)
        {
            Response.Redirect(string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}", appId, redirectUrl, appSecret, Request.QueryString["code"]));
        }
        else
        {
            Response.Redirect(string.Format("https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}&scope={2}", appId, redirectUrl, scope));
        }
        
        
    }
}
